/*
* pps_bom
*/
package com.pitop.mould.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.MouldException;
import com.pitop.mould.api.MouldFeignApi;
import com.pitop.mould.entity.Mould;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 模具
 *
 * @author berton
 */
@Service("mouldSVImpl")
@Slf4j
public class MouldSVImpl {

    @Autowired
    private MouldFeignApi mouldFeignApi;

    /**
     * 加载一个对象Mould
     *
     * @param id * @param code 编码
     * @return Mould
     */
    public Mould load(Long id, String code) {
        if (id == null && code == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.load(id, code);
    }

    /**
     * 加载一个对象Mould 通过id,(将查询关联数据)
     *
     * @param id
     * @return Mould
     */
    public Mould loadById(Long id) {
        if (id == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.loadById(id);
    }

    /**
     * 加载一个对象Mould 通过code,(将查询关联数据)
     *
     * @param code 编码
     * @return Mould
     */
    public Mould loadByCode(String code) {
        if (code == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.loadByCode(code);
    }

    /**
     * 加载一个对象Mould,(将查询关联数据)
     *
     * @param id * @param code 编码
     * @return Mould
     */
    public Mould get(Long id, String code) {
        if (id == null && code == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.get(id, code);
    }

    /**
     * 加载一个对象Mould 通过id,(将查询关联数据)
     *
     * @param id
     * @return Mould
     */
    public Mould getById(Long id) {
        if (id == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.getById(id);
    }

    /**
     * 加载一个对象Mould 通过code,(将查询关联数据)
     *
     * @param code 编码
     * @return Mould
     */
    public Mould getByCode(String code) {
        if (code == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return mouldFeignApi.getByCode(code);
    }

    /**
     * 删除对象Mould
     *
     * @param id * @param code 编码
     */

    public void delete(Long id, String code) {
        if (id == null && code == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldFeignApi.delete(id, code);
    }

    /**
     * 查询Mould分页
     *
     * @param mould    对象
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<Mould>
     */
    public List<Mould> list(Mould mould, int curPage, int pageSize) {
        return mouldFeignApi.list(mould, curPage, pageSize);
    }

    /**
     * 查询Mould分页
     *
     * @param id       * @param code  编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<Mould>
     */
    public List<Mould> list(Long id, String code, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        Mould mould = new Mould();
        mould.setId(id);
        mould.setCode(code);

        return mouldFeignApi.list(mould, curPage, pageSize);
    }

    public int count(Long id, String code) {
        return mouldFeignApi.count(id, code);
    }

    public int count(Mould mould) {
        return mouldFeignApi.count(mould);
    }

    /**
     * 保存
     *
     * @param mould 实体
     * @throws BaseException
     */
    public void save(Mould mould) {
        if (mould == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldFeignApi.build(mould);
    }

    /**
     * 更新
     *
     * @param mould 实体
     * @throws BaseException
     */
    public void modify(Mould mould) {
        if (mould == null) {
            throw new MouldException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        mouldFeignApi.modify(mould);
    }
}
